﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClientAppViaWebService.RestDivisionLogicServiceRef;

namespace ClientAppViaWebService.Forms
{
    public partial class RestDivisionEditForm : OrganizationalDivisionEditForm
    {

        private readonly Int32 ClassID = 14;
        private RestDivisionLogicService restDivService;

        #region Properties.

        public string Location
        {
            get { return txtLocation.Text; }
            set { txtLocation.Text = value; }
        }

        public string Telephone
        {
            get { return txtTelephone.Text; }
            set { txtTelephone.Text = value; }
        }

        #endregion

        public RestDivisionEditForm()
        {
            InitializeComponent();
            restDivService = new RestDivisionLogicService();
        }

        protected override void SetFormProperties(Object _object)
        {  
            RestDivision obj = (_object as RestDivision);
            ID = obj.ID;
            EXT_ID = obj.EXT_ID;
            ParentId = obj.PARENT_ID;
            Class = obj.CLASS_ID;
            ObjName = obj.NAME;
            BossName = obj.BOSS_ID;
            DateCreated = obj.DATE_CREATED;
            Description = obj.DESCRIPTION;
            Email = obj.EMAIL;
            Slogan = obj.SLOGAN;
            Location    = obj.LOCATION_ID;
            Telephone= obj.TELEPHONE;
        }

        protected override Object RetrieveFormProperties()
        {
            RestDivision obj = new RestDivision();
            obj.ID = ID;
            obj.EXT_ID = EXT_ID;
            obj.PARENT_ID = ParentId;
            obj.CLASS_ID = ClassID;
            obj.NAME = ObjName;
            obj.DataBaseName = DataBaseName;
            obj.BOSS_ID = BossName;
            obj.DATE_CREATED = DateCreated;
            obj.DESCRIPTION = Description;
            obj.EMAIL = Email;
            obj.SLOGAN = Slogan;
            obj.LOCATION_ID  = Location;
            obj.TELEPHONE= Telephone;
            return obj;
        }

        protected override void LoadEditFormData(int parentNodeID)
        {
            RestDivision p = restDivService.SelectRestDivision_By_DataBase_And_Id(DataBaseName, parentNodeID);
            SetFormProperties(p);
        }

        protected override void UpdateEntity()
        {
            RestDivision obj = RetrieveFormProperties() as RestDivision;
            restDivService.UpdateRestDivision(obj);
        }

        protected override void InsertEntity()
        {
            RestDivision obj = RetrieveFormProperties() as RestDivision;
            restDivService.InsertRestDivision(obj);
        }
    }
}
